fix: preserve array nulls in drift patches#5179
Open
puneetdixit200 wants to merge 2 commits into
Open
Conversation
Assisted-by: OpenAI GPT-5 Signed-off-by: Puneet Dixit <puneetdixit200@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a drift-detection regression (#5020) by adjusting null-normalization for JSON merge patch diffs so that arrays are preserved rather than recursively “cleaned,” avoiding cases where null-stripping inside arrays can hide real drift in keyed lists (e.g., container specs).
Changes:
- Update
removeNullPatchFieldsto preserve arrays as-is while still removing null-valued fields from map/object nodes. - Update and extend null-normalization tests to assert that nulls inside arrays (including null elements and null object fields) are preserved.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
internal/cmd/agent/deployer/desiredset/diff.go |
Changes null-normalization logic to stop recursing into arrays to avoid masking drift in list-like fields. |
internal/cmd/agent/deployer/desiredset/diff_null_test.go |
Updates expectations and adds coverage to ensure nulls inside arrays are preserved. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Author
|
AI-assisted follow-up on behalf of Puneet: pushed Verified:
|
Assisted-by: OpenAI GPT-5 Signed-off-by: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com>
2f8807d to
e92580f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refers to #5020
Preserve arrays while normalizing null-only map fields in drift patches. JSON merge patch arrays are replacement values, so recursively deleting nulls inside them can hide real drift such as container
imagePullPolicychanges. Map-level null cleanup still handles Helm/default noise.AI assistance: Used OpenAI GPT-5 to inspect and validate this focused change; I reviewed the code and tests.
Additional Information
Tested:
go test ./internal/cmd/agent/deployer/desiredset -run 'Test_Diff_NullPatch|Test_Diff_RemoveNullPatchFields' -count=1\n-go test ./internal/cmd/agent/deployer/desiredset -run 'Test_Diff_HPA' -count=1\n-go test ./internal/cmd/agent/deployer/desiredset -count=1\n-go test -shuffle=on ./internal/cmd/agent/deployer/desiredset -count=1\n-git diff --check\n\n### Checklist\n\n- [ ] I have updated the documentation via a pull request in the fleet-product-docs repository. Not applicable to this bug fix.